<!DOCTYPE html>
<html class="pixel-ratio-3 retina android android-5 android-5-1-1">
<head>
    <title>问诊单</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="">

    <link rel="stylesheet" href="/lib/weui.min.css">
    <link rel="stylesheet" href="/css/jquery-weui.css">
    <link rel="stylesheet" href="/css/home.css">
    <link rel="stylesheet" href="/plugins/fontaw/css/font-awesome.css">
<style>

</style>
</head>
<body  >
<div class="kk-container">
<div class="weui-panel weui-panel_access">
    <div class="weui-cells" id="patientInfo">
        <!--<a class="weui-cell weui-cell_access" href="javascript:;">
            <div class="weui-cell__bd">
                <p>姓名</p>
            </div>
            <div class="weui-cell__ft">李哥 男 42岁</div>
        </a>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>填写时间</p>
            </div>
            <div class="weui-cell__ft">2018-04-23 23:11</div>
        </div>-->
    </div>
</div>

<div class="kk-full-block">
    <div class="kk-full-block-title kk-border-bottom"><i class="fa fa-address-card" aria-hidden="true"></i> 基本信息</div>
    <div class="kk-flex" id="baseInfo">
        <!--<div class="kk-flex-1">
            <p>1982-04-02</p>
            <p>生日</p>
        </div>
        <div class="kk-flex-1">
            <p>172cm</p>
            <p>身高</p>
        </div>
        <div class="kk-flex-1">
            <p>56KG</p>
            <p>体重</p>
        </div>
        <div class="kk-flex-1">
            <p>正常</p>
            <p>BMI</p>
        </div>
        <div class="kk-flex-1">
            <p>无</p>
            <p>常住地</p>
        </div>-->
    </div>

    <!--<div class="kk-border-top">
        <p style="font-size:0.6rem">既往病史</p>
        <p>无</p>
    </div>

    <div class="kk-border-top">
        <p style="font-size:0.6rem">过敏病史</p>
        <p>无</p>
    </div>

    <div class="kk-border-top">
        <p style="font-size:0.6rem">患者主诉</p>
        <p>无</p>
    </div>-->
</div>

<div class="kk-full-block">
    <div class="kk-full-block-title kk-border-bottom"><i class="fa fa-address-card" aria-hidden="true"></i> 问题概要</div>
    <div class="">
        <p style="font-size:0.6rem">身体感觉</p>
        <p id="feel">无</p>
    </div>
    <div class="kk-block-foot" style="background: white;text-align: center" id="detailLink">
        <a href="inquiry-new.html" style="color: green">查看问诊单详情</a>
    </div>
</div>

<div class="kk-full-block" style="margin-bottom: 3rem">
    <div class="kk-full-block-title kk-border-bottom"><i class="fa fa-address-card" aria-hidden="true"></i> 备注（仅医生可见）</div>
    <div class="">
        <textarea style="width: 100%" rows="6" placeholder="医生备注"></textarea>
    </div>
</div>

<div class="kk-foot" style="text-align: center;background-color: green">
 <a href="" style="color:white;font-weight: bold"><div>为他开方</div></a>
</div>
</div>
<script src="/lib/jquery-2.1.4.js"></script>
<script src="/lib/fastclick.js"></script>
<script src="/js/jquery-weui.js"></script>
<script src="/js/home.js"></script>
<script>
 $(function(){
     // 获取患者编号
     var inquiryId = getQueryString("inquiryId");
     // 封装请求参数
     var data = {"inquiryId":inquiryId};
    $.ajax({
        url:"/inquiry/getListByInquiryId",
        type:"post",
        dataType:"json",
        data:data,
        success:function(result){
            console.log("根据患者编号获取问诊单详情"+inquiryId);
            console.log("---："+result.data.patient.age);
            console.log(result.msg);
            // 定义存储患者信息的变量
            var patientInfo = "";
            // 定义存储患者基本信息的变量（身高，体重...)
            var baseInfo = "";

            // 追加患者信息
            patientInfo +="<a class='weui-cell weui-cell_access' href='javascript:;'><div class='weui-cell__bd'>"+
                    "<p>姓名</p></div><div class='weui-cell__ft'>"+result.data.patient.patientname+"  "+result.data.patient.sex+"  "+result.data.patient.age+"岁</div></a>";
            patientInfo +="<div class='weui-cell'><div class='weui-cell__bd'><p>填写时间</p></div>"+
                    "<div class='weui-cell__ft'>"+timestampToTime(result.data.createDate)+"</div></div>";
            $("#patientInfo").html(patientInfo);

            baseInfo += "<div class='kk-flex-1'><p>"+timestampToTime(result.data.patient.birthday)+"</p><p>生日</p></div>"+
                    "<div class='kk-flex-1'><p>"+result.data.patient.hight+"cm</p><p>身高</p></div>"+
                    "<div class='kk-flex-1'><p>"+result.data.patient.weight+"KG</p><p>体重</p></div>"+
                    "<div class='kk-flex-1'><p>正常</p><p>BMI</p></div>"+
                    "<div class='kk-flex-1'><p>无</p><p>常住地</p></div>";
            $("#baseInfo").html(baseInfo);  // 显示到页面

            $("#baseInfo").after("<div class='kk-border-top'><p style='font-size:0.6rem'>既往病史</p><p>"+result.data.patient.inquiryHistory+"</p></div>"+
                    "<div class='kk-border-top'><p style='font-size:0.6rem'>过敏病史</p><p>"+result.data.patient.inquiryAllergy+"</p></div>"+
                    "<div class='kk-border-top'><p style='font-size:0.6rem'>患者主诉</p><p>"+result.data.description+"</p></div>");
            var feel = "";

            $(result.data.detailList).each(function(){
                // 一级分类验证是否是身体感觉
                if(this.content=='身体感觉'){
                    for(var i=0;i<result.data.subList.length;i++){
                        //console.log(result.data.subList[i].answers);

                        $(this.level2List).each(function(){

                            if(this.categoryCode == result.data.subList[i].subjectCode){

                                if(result.data.subList[i].answers.indexOf(',')){
                                    var arr = result.data.subList[i].answers.split(",");
                                    for (var j=0;j<arr.length;j++){
                                        $(this.level3List).each(function(){
                                            //console.log(arr[j]+"===="+this.itemCode);
                                            if(arr[j]==this.itemCode&&this.itemTitle!='正常'&&this.itemTitle!='无以上情况'){
                                                //console.log(arr[j]+"===="+this.itemCode);
                                                feel+=this.itemTitle+",";
                                            }
                                        });
                                    }
                                }else {
                                    $(this.level3List).each(function () {
                                        if(result.data.subList[i].answers==this.itemCode&&this.itemTitle!='正常'&&this.itemTitle!='无以上情况'){
                                            feel+=this.itemTitle+",";
                                        }
                                    });
                                }
                             }
                        });
                    }

                }
            });
            if(feel.length>0) {
                feel = feel.substring(0, feel.length - 1);
                $("#feel").html(feel);
            }
            $("#detailLink").html("<a href='inquiry-new.html?inquiryId="+result.data.id+"' style='color: green'>查看问诊单详情</a>");
        },error:function(){
            console.log("ajax出错");
        }
    });
 });
// 时间戳转日期格式
 function timestampToTime(timestamp) {
     var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
     Y = date.getFullYear() + '-';
     M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
     D = date.getDate() + ' ';
     h = date.getHours() + ':';
     m = date.getMinutes() + ':';
     s = date.getSeconds();
     if(h=="0:" && m=="0:" && s=="0"){
         return Y+M+D;
     }
     return Y+M+D+h+m+s;
 }
</script>
</body>
</html>